package cn.damai.mine.thread.countDownLatch.healthchecker;

import java.util.concurrent.CountDownLatch;

public abstract class BaseHealthChecker implements Runnable {
	
	private CountDownLatch _latch;
	private String _serviceName;
	private boolean _serviceUp;
	private String _resultStr;

	public BaseHealthChecker(CountDownLatch _latch, String _serviceName) {
		super();
		this._latch = _latch;
		this._serviceName = _serviceName;
		this._serviceUp = false;
		this._resultStr = "";
	}

	@Override
	public void run() {
		// TODO Auto-generated method stub
		
		try {
			_resultStr = verifyService();
			_serviceUp = true;
		} catch (Exception e) {
			e.printStackTrace();
			_serviceUp = false;
		} finally {
			if (_latch!=null) {
				_latch.countDown();
			}
		}
	}
	
	public abstract String verifyService();

	public CountDownLatch get_latch() {
		return _latch;
	}

	public void set_latch(CountDownLatch _latch) {
		this._latch = _latch;
	}

	public String get_serviceName() {
		return _serviceName;
	}

	public void set_serviceName(String _serviceName) {
		this._serviceName = _serviceName;
	}

	public boolean is_serviceUp() {
		return _serviceUp;
	}

	public void set_serviceUp(boolean _serviceUp) {
		this._serviceUp = _serviceUp;
	}

	public String get_resultStr() {
		return _resultStr;
	}

	public void set_resultStr(String _resultStr) {
		this._resultStr = _resultStr;
	}
}
